const mongoose = require("../utils/db");
var ShopSchema = new mongoose.Schema({
  name: String,
  price: Number,
  num: Number
});
const Shop = mongoose.model("shops", ShopSchema);
//查询所有
const findShop = () => {
  //从数据库拿到数据
  return new Promise((resolve, reject) => {
    Shop.find((err, docs) => {
      if (err) reject(err);
      else resolve(docs);
    });
  });
  //   return [{ name: "键盘", price: 200, num: 2 }];
};
//插入一条
const inserShop = shopinfo => {
  const shop = new Shop(shopinfo);
  return new Promise((resolve, reject) => {
    shop.save((err, doc) => {
      if (err) reject(err);
      else resolve(doc);
    });
  });
};
module.exports = {
  findShop,
  inserShop
};
